12. Lesson Review
In this lesson we learned…
What is object pooling?
Creating or destroying many objects in a short amount of time can reduce our frame rate. Object pooling helps reduce the process of instantiating or destroying objects in Unity by recycling objects that have been created. Generally, you can always get a performance boost by using object pooling.
While not explicitly covered in the videos, the basic steps for implementing object pooling are as follows:
- Instantiate objects when we need them and add them to a list (so we can track them later).
- When we need an object, check to see if there’s a disabled object by going through our list.
- If there is, reset any information (Clear its velocity, reset its position, etc.) on it and enable it.
- If there’s not, do step 1.
- When you don’t need the object any more (for example, after a bullet collides with something), disable it. You could opt to reset the information here or in the previous step.
How performant are shaders?
Shaders are generally fast because they leverage the GPU, however, specialty shaders, like transparency, are a frequent cause of low frame rate in mobile apps because they require additional passes to render the scene.
Tip: A decent substitution for transparency shaders is a cutout shader.
Why is physics a potential performance hit?
The more objects in the scene that use the physics engine the more computationally expensive it is for the CPU to keep track of it all.
Tip: For simple movement that doesn’t require physics, you can opt to use Unity’s Lerp methods. Click here to read the Unity documentation on Lerp.
How does the art (our 3D models) in our scene affect our performance?
The more simple the model, the less work the GPU has to do to render it. This is the main reason why many mobile VR experiences use a “low poly” art style. The goal is to get the best looking models you can while keeping the amount of faces on it as low as possible.
How is performance affected by the lighting in our scenes?
The biggest performance trade off is between real-time and baked lighting. Real-time lighting is the biggest performance drain on mobile experiences as the lights require constant updates calculating how light should affect surfaces. However, baked lighting does all the computation during the baking process. Baking our lights can take a while, but it’s a process that leads to greater performance overall.
Shadows are also expensive to calculate. Real-time shadows (as with real-time lighting) should be used only when absolutely necessary.